package jpave.manager;

/***
 * XXX Part of Main Edit panel - some in EditPanel 
 * 		which invokes GenerateFileSelector
 * XXX GenerateFileSelector which invokes
 * XXX 		define row files of lib name and library file 
 * 
 * The Read Count file is read in the ManagerData.
 * 
 */
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.Vector;
import java.util.Collections;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;

import util.Debug.ErrorReport;
import util.ui.UserPrompt;

public class EditTransLibPanel extends JPanel {
	private static final String DEFAULT_COMBINED_FILE = "Combined_read_counts.csv";
	private static final long serialVersionUID = -2386563315902142612L;

	public EditTransLibPanel(ManagerFrame parentFrame) {
		theParentFrame = parentFrame;
		
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		createTransReadPanel();
		pnlFileSelector = new GenerateFileSelector();
		pnlFileSelector.setVisible(false);
		
		add(pnlMainPanel);
		add(pnlFileSelector);
		
		setVisible(false);
	}
	// XXX Main edit panel -- this is really bad programming -- some stuff is defined in EditPanel
	private void createTransReadPanel() {
		int width = EditPanel.TEXTFIELD_WIDTH;
	
		pnlMainPanel = new JPanel();
		pnlMainPanel.setLayout(new BoxLayout(pnlMainPanel, BoxLayout.PAGE_AXIS));
		pnlMainPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
		pnlMainPanel.setBackground(ManagerFrame.BGCOLOR);
		
		lblTransLibID = new JLabel(EditPanel.TRANS_LIB_LABELS[0]); // Trans/Read ID
		txtTransLibID = new JTextField(EditPanel.TEXTFIELD_WIDTH_SHORT);
		txtTransLibID.setMaximumSize(txtTransLibID.getPreferredSize());
		txtTransLibID.setMinimumSize(txtTransLibID.getPreferredSize());
		txtTransLibID.addCaretListener(new CaretListener() {
			public void caretUpdate(CaretEvent arg0) {
				btnKeep.setEnabled(txtTransLibID.getText().length() > 0 
						&& ftxtSequenceFile.getText().length() > 0  
						&& txtTransLibID.getText().matches("[A-Za-z]+[A-Za-z0-9_]+") 
						&& txtTransLibID.getText().length() <= 8);
			}
		});

		lblSequenceFile = new JLabel(EditPanel.TRANS_LIB_LABELS[1]); // Sequence file
		ftxtSequenceFile = new FileTextField(theParentFrame, EditPanel.TRANS_LIB_LABELS[1], width);
		ftxtSequenceFile.addCaretListener(new CaretListener() {
			public void caretUpdate(CaretEvent arg0) {
				btnKeep.setEnabled(txtTransLibID.getText().length() > 0 
						&& ftxtSequenceFile.getText().length() > 0  
						&& txtTransLibID.getText().matches("[A-Za-z0-9_]+")  
						&& txtTransLibID.getText().length() <= 8);
			}
		});

		lblQualityFile = new JLabel(EditPanel.TRANS_LIB_LABELS[2]); // Quality file
		ftxtQualityFile = new FileTextField(theParentFrame, EditPanel.TRANS_LIB_LABELS[2], width);

		lblExpressionLevelFile = new JLabel(EditPanel.TRANS_LIB_LABELS[3]); // Expression level
		ftxtExpressionLevelFile = new FileTextField(theParentFrame, EditPanel.TRANS_LIB_LABELS[4], width);
		
		// commented out prefix stuff in rest of code
		lblExpressionLevelPrefix = new JLabel(EditPanel.TRANS_LIB_LABELS[4]);
		txtExpressionLevelPrefix = new JTextField(EditPanel.NUM_FIELD_WIDTH);
		txtExpressionLevelPrefix.setMaximumSize(txtExpressionLevelPrefix.getPreferredSize());
		txtExpressionLevelPrefix.setMinimumSize(txtExpressionLevelPrefix.getPreferredSize());
		
		lblFivePrimeSuffix = new JLabel(EditPanel.TRANS_LIB_LABELS[5]);
		txtFivePrimeSuffix = new JTextField(EditPanel.TEXTFIELD_WIDTH);
		txtFivePrimeSuffix.setMaximumSize(txtFivePrimeSuffix.getPreferredSize());
		txtFivePrimeSuffix.setMinimumSize(txtFivePrimeSuffix.getPreferredSize());

		lblThreePrimeSuffix = new JLabel(EditPanel.TRANS_LIB_LABELS[6]);
		txtThreePrimeSuffix = new JTextField(EditPanel.TEXTFIELD_WIDTH);
		txtThreePrimeSuffix.setMaximumSize(txtThreePrimeSuffix.getPreferredSize());
		txtThreePrimeSuffix.setMinimumSize(txtThreePrimeSuffix.getPreferredSize());
		
		theAttributeLabels = new JLabel[EditPanel.ATTRIBUTE_LABELS.length];
		theAttributeComps = new JComponent[EditPanel.ATTRIBUTE_TYPES.length];
		for(int x=0; x<EditPanel.ATTRIBUTE_LABELS.length; x++) {
			theAttributeLabels[x] = new JLabel(EditPanel.ATTRIBUTE_LABELS[x]);
			theAttributeComps[x] = getComponent(EditPanel.ATTRIBUTE_LABELS[x], EditPanel.ATTRIBUTE_TYPES[x]);
		}
		
		btnGenCountFile = new JButton("Build combined count file");
		btnGenCountFile.setBackground(ManagerFrame.MENUCOLOR);
		btnGenCountFile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(ftxtSequenceFile.getText().length() > 0) {
					pnlMainPanel.setVisible(false);
					pnlFileSelector.setVisible(true); // see GenerateFileSelector in this file 
				}
				else
					JOptionPane.showMessageDialog(theParentFrame, "Please enter Sequence File first", 
							"Build count file", JOptionPane.PLAIN_MESSAGE);
			}
		});

		JPanel row = createRowPanel();
		
		JLabel title = new JLabel("Add or Edit a Sequence Library");
		title.setFont(pnlMainPanel.getFont().deriveFont(Font.BOLD, 18));
		
		row.add(Box.createHorizontalGlue());
		row.add(title);
		row.add(Box.createHorizontalGlue());
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(20));
		
		row = createRowPanel();
		row.add(lblTransLibID);
		if(lblTransLibID.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - 
					lblTransLibID.getPreferredSize().width));
		row.add(txtTransLibID);
		row.add(Box.createHorizontalStrut(10));
		row.add(new JLabel("- Required"));
		
		pnlMainPanel.add(row);
		row = createRowPanel();
		row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH));
		row.add(new JLabel("(Less than 8 characters, no spaces)"));
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(10));

		row = createRowPanel();
		row.add(lblSequenceFile);
		if(lblSequenceFile.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - 
					lblSequenceFile.getPreferredSize().width));
		row.add(ftxtSequenceFile);
		row.add(Box.createHorizontalStrut(10));
		row.add(new JLabel("- Required"));
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(10));

		row = createRowPanel();
		row.add(lblQualityFile);
		if(lblQualityFile.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - 
					lblQualityFile.getPreferredSize().width));
		row.add(ftxtQualityFile);
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(10));

		//row = createRowPanel();
		//row.add(new JLabel("For transcripts or protein sequences:"));
		//pnlMainPanel.add(row);
		
		row = createRowPanel();
		//row.add(Box.createHorizontalStrut(30));
		row.add(lblExpressionLevelFile);
		if(lblExpressionLevelFile.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - 
					lblExpressionLevelFile.getPreferredSize().width));
		row.add(ftxtExpressionLevelFile);
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(5));
		
		row = createRowPanel();
		row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH));
		row.add(btnGenCountFile);
		pnlMainPanel.add(row);

		row = createRowPanel();
		row.add(new JLabel("Sanger ESTs:"));
		pnlMainPanel.add(row);
		
		row = createRowPanel();
		row.add(Box.createHorizontalStrut(30));
		row.add(lblFivePrimeSuffix);
		if(lblFivePrimeSuffix.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - lblFivePrimeSuffix.getPreferredSize().width));
		row.add(txtFivePrimeSuffix);
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(10));

		row = createRowPanel();
		row.add(Box.createHorizontalStrut(30));
		row.add(lblThreePrimeSuffix);
		if(lblThreePrimeSuffix.getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
			row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - lblThreePrimeSuffix.getPreferredSize().width));
		row.add(txtThreePrimeSuffix);
		pnlMainPanel.add(row);
		pnlMainPanel.add(Box.createVerticalStrut(20));
		pnlMainPanel.add(new JLabel("ATTRIBUTES:"));
		pnlMainPanel.add(Box.createVerticalStrut(10));
		
		for(int x=0; x<theAttributeLabels.length; x++) {
			row = createRowPanel();
			row.add(theAttributeLabels[x]);
			if(theAttributeLabels[x].getPreferredSize().width < EditPanel.COLUMN_LABEL_WIDTH)
				row.add(Box.createHorizontalStrut(EditPanel.COLUMN_LABEL_WIDTH - theAttributeLabels[x].getPreferredSize().width));
			row.add(theAttributeComps[x]);
			pnlMainPanel.add(row);
			if(x< (theAttributeLabels.length - 1))
				pnlMainPanel.add(Box.createVerticalStrut(10));
		}
		
		pnlMainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));

		btnKeep = new JButton("Keep");
		btnKeep.setBackground(ManagerFrame.BGCOLOR);
		btnKeep.setEnabled(false);
		btnKeep.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(theParentFrame.transIDValid()) {
					if(theParentFrame.updateTransLibUI()) {
						theParentFrame.updateTransLibProperties();
						setVisible(false);
						theParentFrame.setMainPanelVisible(true);
						theParentFrame.updateUI();
						theParentFrame.saveProject();
					}
					else
						JOptionPane.showMessageDialog(getInstance(), 
								"Error reading the counts.\nSee terminal for more information.");
				}
				else {
					JOptionPane.showMessageDialog(getInstance(), 
							"Sequence ID is a duplicate, please select another ID");
				}			
				theParentFrame.setFrameMode(ManagerFrame.FRAME_MODE_MAIN);
			}
		});
		btnDiscard = new JButton("Discard");
		btnDiscard.setBackground(ManagerFrame.BGCOLOR);
		btnDiscard.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(theParentFrame.isAddTransLib()) {
					theParentFrame.clearCurrentTransLib();
					theParentFrame.updateUI();
				}
				setVisible(false); 
				theParentFrame.setMainPanelVisible(true);
				
				theParentFrame.setFrameMode(ManagerFrame.FRAME_MODE_MAIN);
			}
		});
		btnHelp = new JButton("Help");
		btnHelp.setBackground(ManagerFrame.HELPCOLOR);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				UserPrompt.displayHTMLResourceHelp(theParentFrame, "Sequence Library Help", "html/runSingleTCW/EditTransLibPanel.html");
			}
		});

		JPanel buttonRow = new JPanel();
		buttonRow.setLayout(new BoxLayout(buttonRow, BoxLayout.LINE_AXIS));
		buttonRow.setAlignmentX(Component.CENTER_ALIGNMENT);
		buttonRow.setBackground(ManagerFrame.BGCOLOR);
		
		buttonRow.add(btnKeep);
		buttonRow.add(Box.createHorizontalStrut(15));
		buttonRow.add(btnDiscard);
		buttonRow.add(Box.createHorizontalStrut(15));
		buttonRow.add(btnHelp);
		
		buttonRow.setMaximumSize(buttonRow.getPreferredSize());
		buttonRow.setMinimumSize(buttonRow.getPreferredSize());
		
		JPanel outerPanel = new JPanel();
		outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.PAGE_AXIS));
		outerPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		outerPanel.setBackground(ManagerFrame.BGCOLOR);
		outerPanel.add(buttonRow);

		pnlMainPanel.add(Box.createVerticalStrut(20));
		pnlMainPanel.add(outerPanel);
		pnlMainPanel.setMaximumSize(pnlMainPanel.getPreferredSize());
		pnlMainPanel.setMinimumSize(pnlMainPanel.getPreferredSize());
		
		Dimension d = outerPanel.getPreferredSize();
		d.width = pnlMainPanel.getPreferredSize().width;
		outerPanel.setPreferredSize(d);
		outerPanel.setMaximumSize(outerPanel.getPreferredSize());
		outerPanel.setMinimumSize(outerPanel.getPreferredSize());
	}
	private JPanel createRowPanel() {
		JPanel retVal = new JPanel();
		retVal.setLayout(new BoxLayout(retVal, BoxLayout.LINE_AXIS));
		retVal.setAlignmentX(Component.LEFT_ALIGNMENT);
		retVal.setBackground(ManagerFrame.BGCOLOR);
		
		return retVal;
	}
	private JComponent getComponent(String key, Class<?> type) {
		JComponent retVal = null;
		if(type == String.class) {
			retVal = new JTextField(EditPanel.TEXTFIELD_WIDTH);
			retVal.setMaximumSize(retVal.getPreferredSize());
			((JTextField)retVal).addCaretListener(updateListener);
		}
		else if(type == File.class) {
			retVal = new FileTextField(theParentFrame, key, EditPanel.TEXTFIELD_WIDTH);
			((FileTextField)retVal).addCaretListener(updateListener);
			((FileTextField)retVal).addActionListener(fileSelectListener);
		}
		else if(type == Integer.class) {
			retVal = new JTextField(EditPanel.NUM_FIELD_WIDTH);
			retVal.setMaximumSize(retVal.getPreferredSize());
			((JTextField)retVal).addCaretListener(updateListener);
		}
		else if(type == Boolean.class) {
			retVal = new JCheckBox();
		}
		retVal.setBackground(ManagerFrame.BGCOLOR);
		
		return retVal;
	}
	private ActionListener fileSelectListener = new ActionListener() {
		public void actionPerformed(ActionEvent arg0) {
		}
	};
	// doesn't do anything
	private CaretListener updateListener = new CaretListener() {
		public void caretUpdate(CaretEvent e) {
		}
	};
	
	public EditTransLibPanel getInstance() { return this; }

	/*******************************************************************
	 * called by ManagerFrame
	 */
	public Object getValue(String symbol) {
		Object retVal = null;
		if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[0])) retVal = txtTransLibID.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[1])) retVal = ftxtSequenceFile.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[2])) retVal = ftxtQualityFile.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[3])) retVal = ftxtExpressionLevelFile.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[4])) retVal = txtExpressionLevelPrefix.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[5])) retVal = txtFivePrimeSuffix.getText();
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[6])) retVal = txtThreePrimeSuffix.getText();
		else 
		{
			for(int x=0; x<EditPanel.ATTRIBUTE_SYMBOLS.length && retVal == null; x++) {
				if(EditPanel.ATTRIBUTE_SYMBOLS[x].equals(symbol)) {
					if(theAttributeComps[x] instanceof JTextField)
						retVal = new String(((JTextField)theAttributeComps[x]).getText());
					else if(theAttributeComps[x] instanceof FileTextField)
						retVal = new String(((FileTextField)theAttributeComps[x]).getText());
					else if(theAttributeComps[x] instanceof JCheckBox)
						retVal = new Boolean(((JCheckBox)theAttributeComps[x]).isSelected());
				}
			}
		}	
		return retVal;
	}
	
	public String getOldTransLibID() { return strOldTransLibID; }
	
	public void setValue(String symbol, Object value) {
		if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[0])) {
			strOldTransLibID = (String)value;
			txtTransLibID.setText((String)value);
		}
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[1])) ftxtSequenceFile.setText((String)value);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[2])) ftxtQualityFile.setText((String)value);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[3])) ftxtExpressionLevelFile.setText((String)value);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[4])) txtExpressionLevelPrefix.setText((String)value);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[5])) txtFivePrimeSuffix.setText((String)value);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[6])) txtThreePrimeSuffix.setText((String)value);
		else { 
			boolean valueSet = false;
			for(int x=0; x<EditPanel.ATTRIBUTE_SYMBOLS.length && !valueSet; x++) {
				if(EditPanel.ATTRIBUTE_SYMBOLS[x].equals(symbol)) {
					valueSet = true;
					
					if(theAttributeComps[x] instanceof JTextField)
						((JTextField)theAttributeComps[x]).setText((String)value);
					else if(theAttributeComps[x] instanceof FileTextField)
						((FileTextField)theAttributeComps[x]).setText((String)value);
					else if(theAttributeComps[x] instanceof JCheckBox)
						((JCheckBox)theAttributeComps[x]).setSelected((Boolean)value);
				}
			}
		}
	}
	
	public void setEnabled(String symbol, boolean enable) {
		boolean enabled = enable; 
		if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[0])) txtTransLibID.setEnabled(enabled);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[1])) ftxtSequenceFile.setEnabled(enabled);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[2])) ftxtQualityFile.setEnabled(enabled);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[3])) {
			ftxtExpressionLevelFile.setEnabled(enabled);
			btnGenCountFile.setEnabled(enabled);
		}
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[5])) txtFivePrimeSuffix.setEnabled(enabled);
		else if(symbol.equals(EditPanel.TRANS_LIB_SYMBOLS[6])) txtThreePrimeSuffix.setEnabled(enabled);
		else { 
			boolean valueSet = false;
			for(int x=0; x<EditPanel.ATTRIBUTE_SYMBOLS.length && !valueSet; x++) {
				if(EditPanel.ATTRIBUTE_SYMBOLS[x].equals(symbol)) {
					valueSet = true;
					
					if(theAttributeComps[x] instanceof JTextField)
						((JTextField)theAttributeComps[x]).setEnabled(enabled);
					else if(theAttributeComps[x] instanceof FileTextField)
						((FileTextField)theAttributeComps[x]).setEnabled(enabled);
					else if(theAttributeComps[x] instanceof JCheckBox)
						((JCheckBox)theAttributeComps[x]).setEnabled(enabled);
				}
			}
		}
	}
	
	public void clearCountFileList() { pnlFileSelector.clearCountFileList(); }
	public void addCountFile(String file, String header) { pnlFileSelector.addFile(file, header); }
	public int getNumCountFiles() { return pnlFileSelector.theFiles.size(); }
	public String getCountFileAt(int pos) { return pnlFileSelector.theFiles.get(pos); }
	public String getCountHeaderAt(int pos) { return pnlFileSelector.theHeaders.get(pos); }

	/****************************************************
	 * EditTransLibPanel private variables
	 */
	private ManagerFrame theParentFrame = null;
	
	private JPanel pnlMainPanel = null;
	
	private JLabel lblTransLibID = null;
	private JTextField txtTransLibID = null;
	
	private JLabel lblSequenceFile = null;
	private FileTextField ftxtSequenceFile = null;	
	
	private JLabel lblQualityFile = null;
	private FileTextField ftxtQualityFile = null;	
	
	private JLabel lblExpressionLevelFile = null;
	private FileTextField ftxtExpressionLevelFile = null;
	
	private JLabel lblExpressionLevelPrefix = null;
	private JTextField txtExpressionLevelPrefix = null;
	
	private JLabel lblFivePrimeSuffix = null;
	private JTextField txtFivePrimeSuffix = null;
	
	private JLabel lblThreePrimeSuffix = null;
	private JTextField txtThreePrimeSuffix = null;
	
	private JLabel [] theAttributeLabels = null;
	private JComponent [] theAttributeComps = null;
	
	private JButton btnGenCountFile = null;

	private JButton btnKeep = null;
	private JButton btnDiscard = null;
	private JButton btnHelp = null;
	
	private GenerateFileSelector pnlFileSelector = null;
	private File currentDir = null;
	private String strOldTransLibID = "";
	
	private String removeLib(String path) {
		String libPath = theParentFrame.getLibPath().getAbsolutePath();
		int index = path.indexOf(libPath);
		if(index >= 0) return path.substring(index + libPath.length() + 1);
		else return path;
	}
	/*****************************************************************
	 * Class for reading files
	 */
	public class FileTextField extends JPanel {
		private static final long serialVersionUID = 6670096855895700182L;
		
		private FileTextField(ManagerFrame parentFrame, final String label, int size) {
			theParentFrame = parentFrame;
			setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
			setAlignmentX(Component.LEFT_ALIGNMENT);
			setBackground(ManagerFrame.BGCOLOR);
			
			txtValue = new JTextField(size);
			Dimension dTxt = txtValue.getPreferredSize(); 
			txtValue.setMaximumSize(dTxt);
			txtValue.setMinimumSize(dTxt);
			
			btnFindFile = new JButton("...");
			btnFindFile.setBackground(ManagerFrame.BGCOLOR);
			Dimension dBtn = new Dimension();
			dBtn.width = btnFindFile.getPreferredSize().width;
			dBtn.height = dTxt.height;
			
			btnFindFile.setMaximumSize(dBtn);
			btnFindFile.setMinimumSize(dBtn);
			btnFindFile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					try {
						JFileChooser fc = new JFileChooser();	
						if(currentDir == null)
							currentDir = theParentFrame.getLibPath();
						fc.setCurrentDirectory(currentDir); 
						
						if(fc.showOpenDialog(getInstance()) == JFileChooser.APPROVE_OPTION) {
								String path = fc.getSelectedFile().getAbsolutePath();
								currentDir = new File (path); 
								if(label.equals(EditPanel.TRANS_LIB_LABELS[1])) {// Sequence file
									updateTitle(path);
									verifyFasta(path);
								}
								else if(label.equals(EditPanel.TRANS_LIB_LABELS[2])) {// Quality file
									verifyQFasta(path);
								}
								path = removeLib(path);
								txtValue.setText(path); 
						}
					}
					catch(Exception e) {ErrorReport.prtReport(e, "Error finding file");}
				}});
			
			add(txtValue);
			add(btnFindFile);
		}
		private void updateTitle(String title) {
			int titleIdx = -1;

			for(int x=0; x<theAttributeLabels.length && titleIdx < 0; x++) {
				if(theAttributeLabels[x].getText().equals("Title"))
					titleIdx = x;
			}
			
			if(titleIdx >= 0) {
				String path = ((JTextField)theAttributeComps[titleIdx]).getText();
				if(path.length() == 0) {
					int pos = 0;
					while((pos = title.indexOf('/')) >= 0) {
						title = title.substring(pos+1, title.length());
					}
					if((pos = title.indexOf('.')) >=0)
						title = title.substring(0, pos);
					((JTextField)theAttributeComps[titleIdx]).setText(title);
				}
			}		
		}
		private void verifyFasta(String seqfile) {
			try {
				boolean good=true;
				BufferedReader br = new BufferedReader(new FileReader(seqfile));
				String line="";
				while(line.equals(""))line = br.readLine().trim();
				if (!line.startsWith(">")) {
					System.err.println("First non-blank line does not start with >\n" + "Line: " + line);
					good=false;
				}
				else {
					line = br.readLine().trim();
					if (!line.matches("^[a-zA-Z]+$")) {
						System.err.println("First line after > is not all characters.\n" + "Line: " + line);
						good=false;
					}
				} 
				if (!good) {
					JOptionPane.showMessageDialog(null, "Sequence file may not be fasta \n" + seqfile, "Warn", JOptionPane.PLAIN_MESSAGE);
					System.err.println("Error: " + seqfile + " -- is not a fasta file");
				}
			}
			catch (Exception e) {ErrorReport.prtReport(e, "Verifying sequence file");}
		}
		private void verifyQFasta(String qualfile) {;
			try {
				boolean good=true;
				BufferedReader br = new BufferedReader(new FileReader(qualfile));
				String line="";
				while(line.equals(""))line = br.readLine().trim();
				if (!line.startsWith(">")) {
					System.err.println("First non-blank line does not start with >\n" + "Line: " + line);
					good=false;
				}
				else {
					line = br.readLine().trim();
					if (!line.matches("^[0-9 ]+")) {
						System.err.println("First line after > has characters other than digits and blanks.\n" + "Line: " + line);
						good=false;
					}
				} 
				if (!good) {
					JOptionPane.showMessageDialog(null, "Quality file may not be correct \n" + qualfile, "Warn", JOptionPane.PLAIN_MESSAGE);
					System.err.println("Error: " + qualfile + " -- is not a fasta file");
				}
			}
			catch (Exception e) {ErrorReport.prtReport(e, "Verifying sequence file");}
		}
		public void addCaretListener(CaretListener l) { txtValue.addCaretListener(l); }
		public void addActionListener(ActionListener l) { btnFindFile.addActionListener(l); }
		
		public void setText(String text) { txtValue.setText(text); }
		public String getText() { return txtValue.getText(); }
		
		public String getAbsoluteText() // WN was not working with files selected from the default location
		{
			if (txtValue.getText().startsWith("/")) return txtValue.getText();
			else
				return theParentFrame.getLibPath().getAbsolutePath() + "/" + txtValue.getText();
		}
		
		public void setEnabled(boolean enabled) {
			txtValue.setEnabled(enabled);
			btnFindFile.setEnabled(enabled);
		}
		
		private ManagerFrame theParentFrame = null;
		
		private JTextField txtValue = null;
		private JButton btnFindFile = null;
	}

	// XXX GenerateFileSelector 
	private class GenerateFileSelector extends JPanel {
		private static final long serialVersionUID = 7368072364188049095L;

		public GenerateFileSelector() {
			theFiles = new Vector<String> ();
			theHeaders = new Vector<String> ();
			buildGenerateFilePanel();
		}
		
		public void addFile(String file, String header) {
			theFiles.add(file);
			theHeaders.add(header);
			theModel.fireTableDataChanged();
		}
		
		public void clearCountFileList() {
			theFiles.clear();
			theHeaders.clear();
		}
		
		private void buildGenerateFilePanel() { 
			setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
			setBackground(Color.WHITE);
			
			pnlTable = new JPanel();
			pnlTable.setLayout(new BoxLayout(pnlTable, BoxLayout.PAGE_AXIS));
			pnlTable.setBackground(Color.WHITE);
			pnlTable.setAlignmentX(Component.CENTER_ALIGNMENT);
			pnlTable.setBackground(ManagerFrame.BGCOLOR);

			theModel = new TheTableModel();
			theTable = new JTable(theModel);
			theTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
				public void valueChanged(ListSelectionEvent arg0) {
					btnRemoveFile.setEnabled(theTable.getSelectedRowCount() > 0);
					btnEditFile.setEnabled(theTable.getSelectedRowCount() > 0);
				}
			});

			JScrollPane sPane = new JScrollPane(theTable);
			sPane.getViewport().setBackground(Color.WHITE);
			pnlTable.add(sPane);

			pnlButton1 = new JPanel();
			pnlButton1.setLayout(new BoxLayout(pnlButton1, BoxLayout.LINE_AXIS));
			pnlButton1.setAlignmentX(Component.CENTER_ALIGNMENT);
			pnlButton1.setBackground(Color.WHITE);
			pnlButton1.setBackground(ManagerFrame.BGCOLOR);
			
			pnlButton2 = new JPanel();
			pnlButton2.setLayout(new BoxLayout(pnlButton2, BoxLayout.LINE_AXIS));
			pnlButton2.setAlignmentX(Component.CENTER_ALIGNMENT);
			pnlButton2.setBackground(Color.WHITE);
			pnlButton2.setBackground(ManagerFrame.BGCOLOR);
			
			btnAddDir = new JButton("Add Directory of Files");
			btnAddDir.setBackground(Color.WHITE);
			btnAddDir.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if(currentDir == null)
						currentDir = theParentFrame.getLibPath();
					nCurrentIndex = -1;
					
					JFileChooser fc = new JFileChooser(currentDir);
					fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
					int retVal = fc.showDialog(theParentFrame, "Add Files from Directory");
					
					if(retVal == JFileChooser.APPROVE_OPTION) {
						String dir = fc.getSelectedFile().getPath(); 
						if (!new File(dir).isDirectory()) { // happens on mac
							JOptionPane.showMessageDialog(null,  
									"Please select directory name to open", "Error reading directory", 
									JOptionPane.PLAIN_MESSAGE);
						}
						else {
							addFilesFromDir(dir);
							currentDir = fc.getCurrentDirectory();
							theModel.fireTableDataChanged();
						}
					}
				}
			});
			
			btnAddFile = new JButton("Add Lib");
			btnAddFile.setBackground(Color.WHITE);
			btnAddFile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					if(currentDir == null)
						currentDir = theParentFrame.getLibPath();

					nCurrentIndex = -1;
					
					JFileChooser fc = new JFileChooser(currentDir);
					int retVal = fc.showOpenDialog(theParentFrame);
					// XXX
					if(retVal == JFileChooser.APPROVE_OPTION) {
						pnlTable.setVisible(false);
						pnlButton1.setVisible(false);
						pnlButton2.setVisible(false);
						pnlEditRow.resetValues();
						pnlEditRow.setVisible(true);
						String path = removeLib(fc.getSelectedFile().getPath());
						pnlEditRow.setValues(path, "");
						
						currentDir = fc.getCurrentDirectory();
						theModel.fireTableDataChanged();
					}
				}
			});
			btnEditFile = new JButton("Edit Lib");
			btnEditFile.setBackground(Color.WHITE);
			btnEditFile.setEnabled(false);
			btnEditFile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					pnlTable.setVisible(false);
					pnlButton1.setVisible(false);
					pnlButton2.setVisible(false);
					pnlEditRow.resetValues();
					pnlEditRow.setVisible(true);
					
					nCurrentIndex = theTable.getSelectedRow();
					
					pnlEditRow.setValues(theFiles.get(theTable.getSelectedRow()), 
							theHeaders.get(theTable.getSelectedRow()));
					
					theModel.fireTableDataChanged();
				}
			});
			btnRemoveFile = new JButton("Remove Lib");
			btnRemoveFile.setEnabled(false);
			btnRemoveFile.setBackground(Color.WHITE);
			btnRemoveFile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					nCurrentIndex = theTable.getSelectedRow();
					theFiles.remove(theTable.getSelectedRow());
					theHeaders.remove(theTable.getSelectedRow());
					theModel.fireTableDataChanged();
				}
			});
			btnCancel = new JButton("Cancel");
			btnCancel.setBackground(Color.WHITE);
			btnCancel.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					pnlMainPanel.setVisible(true);
					pnlFileSelector.setVisible(false);
				}
			});
			btnSave = new JButton("Save");
			btnSave.setBackground(Color.WHITE);
			btnSave.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					theParentFrame.saveProject();
				}
			});
			btnBuildFile = new JButton("Generate File");
			//btnBuildFile.setBackground(ManagerFrame.FUNCTIONCOLOR);
			btnBuildFile.setEnabled(true);
			btnBuildFile.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					generateFile();
					pnlMainPanel.setVisible(true);
					pnlFileSelector.setVisible(false);
				}
			});
			btnGenCountHelp = new JButton("Help");
			btnGenCountHelp.setBackground(ManagerFrame.HELPCOLOR);
			btnGenCountHelp.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					UserPrompt.displayHTMLResourceHelp(theParentFrame, "Expression Library Help", 
							"html/runSingleTCW/EditExpLibPanelGenCounts.html");
				}
			});
		
			pnlButton1.add(btnAddDir);
			pnlButton1.add(Box.createHorizontalStrut(5));
			pnlButton1.add(btnAddFile);
			pnlButton1.add(Box.createHorizontalStrut(5));
			pnlButton1.add(btnEditFile);
			pnlButton1.add(Box.createHorizontalStrut(5));
			pnlButton1.add(btnRemoveFile);
			pnlButton1.add(Box.createHorizontalStrut(5));
			pnlButton1.add(btnCancel);
			pnlButton1.setMaximumSize(pnlButton1.getPreferredSize());
			pnlButton1.setMinimumSize(pnlButton1.getPreferredSize());
			
			pnlButton2.add(btnSave);
			pnlButton2.add(Box.createHorizontalStrut(5));
			pnlButton2.add(btnBuildFile);
			pnlButton2.add(Box.createHorizontalStrut(5));
			pnlButton2.add(btnGenCountHelp);
			pnlButton2.setMaximumSize(pnlButton2.getPreferredSize());
			pnlButton2.setMinimumSize(pnlButton2.getPreferredSize());
			
			pnlEditRow = new DefineRowValue();
			pnlEditRow.setVisible(false);
			
			add(pnlTable);
			add(Box.createVerticalStrut(10));
			add(pnlButton1);
			add(Box.createVerticalStrut(10));
			add(pnlButton2);
			add(pnlEditRow);
			
			setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		}
		// read directory of files and enter into table for Generate Counts
		private void addFilesFromDir(String dirStr) {
			try {
				System.err.println("Loading files from " +dirStr);
				File dir = new File(dirStr);
				File[] files = dir.listFiles();
				
				for (int i=0; i<files.length; i++) {
					String name = files[i].getName();
					if (name.startsWith(".")) continue;
					
					String fullname = dirStr + "/" + name;
					
					if (!checkCountFile(fullname)) {
						System.err.println("Ignoring " + name);
						continue;
					}
					
					int index = name.indexOf(".");
					String prefix;
					if (index == -1) prefix = name;
					else prefix = name.substring(0,index);
					
					String fname = removeLib(dirStr + "/" + name);
					theFiles.add(fname);
					theHeaders.add(prefix);
				}
			}
			catch (Exception e) {
				ErrorReport.reportError(e, "Could not read folder");
			}
		}
		private boolean checkCountFile(String file) {
			try {
				File f = new File (file);
				if (f.isDirectory()) return false;
				if (!f.canRead()) {
					System.err.println("Unreadeable " + file);
					return false;
				}
				
				BufferedReader br = new BufferedReader(new FileReader(file));
				String line;
				while((line = br.readLine())!= null) {
					if (line.startsWith("#")) continue;
					if (line.trim().equals("")) continue;	
					String [] vals = line.split("[\\s]+");
					try {
						Long.parseLong(vals[1]);
						return true;
					}
					catch (Exception e) {
						return false;
					}
				}
			}
			catch (Exception e) {
				ErrorReport.prtReport(e, "Error reading " + file);
			}
			return false;
		}
		/*************************************************************
		 *XXX Generate File
		 */
		private void generateFile() {
			if(theFiles.size() == 0) {
				System.out.println("Error: no files selected");
				return;
			}			
			try {
		         System.out.println("Generating combined the count file - this takes a while");
		         // get all seqIDs from sequence file to make sure they correspond to read count files
				ArrayList <String> seqIDs = new ArrayList<String> ();
				BufferedReader br = new BufferedReader(new FileReader(ftxtSequenceFile.getAbsoluteText()));
				String line = br.readLine();
				while(line != null) {
					if(line.startsWith(">")) {
						seqIDs.add(line.substring(1).split("\\s+")[0]);
					}
					line = br.readLine();
				}
				Collections.sort(seqIDs);		
				System.out.println("Sequences: " + seqIDs.size());
				
				Vector<long []> theCounts = new Vector<long []> ();
				String libPath = theParentFrame.getLibPath().getAbsolutePath();
				
				for(int x=0; x<theFiles.size(); x++) {
					String filename = theFiles.get(x);
					String prtname = filename;
					
					if (filename.startsWith("/")) // CAS 7/3/13
						prtname = filename.substring(filename.lastIndexOf("/"));
					else
						filename = libPath + "/" + filename;				
					System.out.println("Reading " + prtname);
					
					long [] theDECounts = new long[seqIDs.size()];
					for(int y=0; y<theDECounts.length; y++)
						theDECounts[y] = 0;
					
					br = new BufferedReader(new FileReader(filename));
					line = br.readLine();
					int lineCount = 0;
					while(line != null) {
						if (line.startsWith("#")) continue;
						if (line.trim().equals("")) continue;
						
						lineCount++;
						if (lineCount % 100 == 0) System.out.print("Reading line " + lineCount + "\r");
						String [] vals = line.split("[\\s]+");
						
						String seqID = vals[0].trim();
						long count;
						try {
							count = Long.parseLong(vals[1]);
						}
						catch (Exception e) {
							showError("Incorrect line: " + line);
							return;
						}
						
						int index = Collections.binarySearch(seqIDs, seqID);						
						if (index < 0) {
							showError(seqID + " not in sequence file ");
							return;
						}
						else theDECounts[index] = count;
						
						line = br.readLine();
					}
					System.out.println("Lines read: " + lineCount + "        ");
					theCounts.add(theDECounts);
				}
				
				File outFile = new File(theParentFrame.getLibPath().getAbsolutePath() + "/" + DEFAULT_COMBINED_FILE);
				System.out.println("Writing file " + DEFAULT_COMBINED_FILE + " in " + 
							theParentFrame.getLibPath().getAbsolutePath());
				PrintWriter out = new PrintWriter(new FileWriter(outFile));
				
				out.print("Sequence  ");
				for(int x=0; x<theHeaders.size(); x++) {
					out.print(theHeaders.get(x) + " ");
				}
				out.println();
				
				for(int x=0; x<seqIDs.size(); x++) {
					out.print(seqIDs.get(x));
					for(int y=0; y<theCounts.size(); y++) {
						out.print("\t" + theCounts.get(y)[x]);
					}
					out.println();
					out.flush();
				}
				
				out.close();
				ftxtExpressionLevelFile.setText(DEFAULT_COMBINED_FILE); 
			}
			catch(Exception e) {
				ErrorReport.prtReport(e, "Error generating count file");
			}
		}
		private void showError(String msg) {
			System.err.println("Abort generate file: " + msg);
			JOptionPane.showMessageDialog(theParentFrame, msg, 
					"Fatal Error", JOptionPane.PLAIN_MESSAGE);
		}
		private class TheTableModel extends AbstractTableModel {
			private static final long serialVersionUID = 7134027422140841320L;

			public String getColumnName(int column) {
				if(column == 0)
					return "Lib name";
				return "File Name";
			}
			
			public int getColumnCount() {
				return 2;
			}

			public int getRowCount() {
				return theFiles.size();
			}

			public Object getValueAt(int row, int col) {
				if(col == 0)
					return theHeaders.get(row);
				return theFiles.get(row);
			}
			
		}
		
		// XXX define library file and lib name
		private class DefineRowValue extends JPanel {
			private static final long serialVersionUID = 4128023510335161928L;

			public DefineRowValue() {
				setBackground(Color.WHITE);
				
				pnlMain = new JPanel();
				pnlMain.setAlignmentX(Component.CENTER_ALIGNMENT);
				pnlMain.setBackground(Color.WHITE);
				pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.PAGE_AXIS));			
				
			// Row1 Input file
				JPanel row = new JPanel();
				row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
				row.setBackground(Color.WHITE);
				row.add(new JLabel("File"));
				row.add(Box.createHorizontalStrut(5));
				
				txtFile = new JTextField(30);
				txtFile.setMaximumSize(txtFile.getPreferredSize());
				txtFile.setMinimumSize(txtFile.getPreferredSize());
				txtFile.addCaretListener(new CaretListener() {
					public void caretUpdate(CaretEvent arg0) {
						updateButtons();
					}
				});
				
				btnSelectFile = new JButton("...");
				btnSelectFile.setBackground(Color.WHITE);
				btnSelectFile.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						if(currentDir == null)
							currentDir = theParentFrame.getLibPath();
						JFileChooser fc = new JFileChooser(currentDir);
						
						int retVal = fc.showOpenDialog(theParentFrame);
						
						if(retVal == JFileChooser.APPROVE_OPTION) {
							txtFile.setText(fc.getSelectedFile().getAbsolutePath());
						}
					}
				});
				
				Dimension d = btnSelectFile.getPreferredSize();
				d.height = txtFile.getPreferredSize().height;
				btnSelectFile.setPreferredSize(d);
				
				row.add(txtFile);
				row.add(btnSelectFile);	
				pnlMain.add(row);
				pnlMain.add(Box.createVerticalStrut(10));
						
			// Row 2 lib name
				row = new JPanel();
				row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
				row.setBackground(Color.WHITE);
				
				row.add(new JLabel("Lib name"));
				row.add(Box.createHorizontalStrut(10));
				
				txtHeader = new JTextField(15);
				txtHeader.setMaximumSize(txtHeader.getPreferredSize());
				txtHeader.setMinimumSize(txtHeader.getPreferredSize());
				txtHeader.addCaretListener(new CaretListener() {
					public void caretUpdate(CaretEvent arg0) {
						updateButtons();
					}
				});
				row.add(txtHeader);
				row.add(Box.createVerticalStrut(15));
				pnlMain.add(row);
				pnlMain.add(Box.createVerticalStrut(15));

			// Row 3-4 labels
				row = new JPanel();
				row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
				row.setBackground(Color.WHITE);
				row.add(new JLabel("The name must be unique. It will be used as the column heading."));
				row.add(Box.createVerticalStrut(15));
				pnlMain.add(row);
				pnlMain.add(Box.createVerticalStrut(15));
				
				row = new JPanel();
				row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
				row.setBackground(Color.WHITE);
				row.add(new JLabel("Give replicates the same name suffixed with a unique number."));
				row.add(Box.createVerticalStrut(15));
				pnlMain.add(row);
				pnlMain.add(Box.createVerticalStrut(15));
				
			// Row 5 Keep, Discard
				row = new JPanel();
				row.setLayout(new BoxLayout(row, BoxLayout.LINE_AXIS));
				row.setBackground(Color.WHITE);
				
				btnKeep = new JButton("Keep");
				btnKeep.setBackground(Color.WHITE);
				btnKeep.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						if(nCurrentIndex < 0) { //add
							theFiles.add(txtFile.getText());
							theHeaders.add(txtHeader.getText());
						} //edit
						else {
							theFiles.set(nCurrentIndex, txtFile.getText());
							theHeaders.set(nCurrentIndex, txtHeader.getText());
						}
						
						theModel.fireTableDataChanged();
						
						pnlTable.setVisible(true);
						pnlButton1.setVisible(true);
						pnlButton2.setVisible(true);
						setVisible(false);
					}
				});
				
				btnDiscard = new JButton("Discard");
				btnDiscard.setBackground(Color.WHITE);
				btnDiscard.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						pnlTable.setVisible(true);
						pnlButton1.setVisible(true);
						pnlButton2.setVisible(true);
						setVisible(false);
					}
				});
				
				row.add(btnKeep);
				row.add(Box.createHorizontalStrut(10));
				row.add(btnDiscard);
				
				pnlMain.add(row);
				pnlMain.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
				
				add(pnlMain);
			}
			
			private void updateButtons() {
				btnKeep.setEnabled(txtFile.getText().length() > 0 && txtHeader.getText().length() > 0);
			}
			
			public void setValues(String file, String header) {
				txtFile.setText(file);
				txtHeader.setText(header);
			}
			
			public void resetValues() {
				txtFile.setText("");
				txtHeader.setText("");
				btnKeep.setEnabled(false);
			}
			
			private JPanel pnlMain = null;
			
			private JTextField txtFile = null;
			private JButton btnSelectFile = null;
			
			private JTextField txtHeader = null;
			
			private JButton btnKeep = null;
			private JButton btnDiscard = null;
		}
		
		private JTable theTable = null;
		private TheTableModel theModel = null;
		
		private JButton btnAddDir = null;
		private JButton btnAddFile = null;
		private JButton btnEditFile = null;
		private JButton btnRemoveFile = null;
		private JButton btnCancel = null;
		private JButton btnSave = null;
		private JButton btnBuildFile = null;
		private JButton btnGenCountHelp = null;
		
		private Vector<String> theFiles = null;
		private Vector<String> theHeaders = null;
		
		private JPanel pnlTable = null;
		private JPanel pnlButton1 = null;
		private JPanel pnlButton2 = null;
		private DefineRowValue pnlEditRow = null;
		
		private int nCurrentIndex = -1;
	}	
}
